package com.pension.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @ClassName: InsertMysql
 * @Description: GOOD
 * @author: ZZL
 * @date: 2021/3/2  10:45
 */
public class InsertMysql {

    public static void main(String[] arg){
        Connection conn;
        PreparedStatement stmt;
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:6666/pensioncloud?useUnicode=true&characterEncoding=UTF-8";
        String user = "root";
        String password = "root";
        String sql = " insert into p_service(realname,s_time,s_day,s_type,s_class,s_place,s_address) values(?,?,?,?,?,?,?)";

        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
            stmt = (PreparedStatement) conn.prepareStatement(sql);
            for (int i = 0; i <900 ; i++) {
                 if(i%100==0){
                     System.out.println("执行了100次");
                 }
            stmt.setString(1, RandomName.randomName(1));
            stmt.setString(2, RandomName.randomName(2));
            stmt.setString(3, RandomName.randomName(9));
            stmt.setString(4, RandomName.randomName(11));
            stmt.setString(5,RandomName.randomName(13));
            stmt.setString(6,RandomName.randomName(12));
            stmt.setString(7,RandomName.randomName(10));
            stmt.executeUpdate();
            }
        } catch (ClassNotFoundException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
    }

}
